package com.yxw.live_vod_boot.controller;

import com.yxw.live_vod_backend_facade.dto.ProductFeignQueryDTO;
import com.yxw.live_vod_backend_facade.vo.ProductSpecificationVO;
import com.yxw.live_vod_backend_facade.vo.ProductVO;
import com.yxw.live_vod_boot.dto.AddVodProductDto;
import com.yxw.live_vod_boot.dto.VodProductClickDto;
import com.yxw.live_vod_boot.service.ProductService;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Administrator
 */
@RestController
@Api(value = "商品管理", tags = "商品管理")
@Slf4j
@RequestMapping("/api/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @ApiOperation("根据Id获取商品详情")
    @PostMapping("/get_product_by_id")
    public BaseResult<ProductVO> getProductById(@RequestParam("productId") Long productId){
        return productService.getProductById(productId);
    }

    @ApiOperation("获取商品列表")
    @PostMapping("/get_product_list")
    public BaseResult<PageVO<ProductVO>> getProductList(@RequestBody @Validated ProductFeignQueryDTO queryDTO){
        return productService.getProductList(queryDTO);
    }

    @ApiOperation("根据商品ID获取对应商品规格列表信息")
    @PostMapping("/get_product_specification_by_id")
    public BaseResult<List<ProductSpecificationVO>> getProductSpecificationById(@RequestParam("productId") Long productId){
        return productService.getProductSpecificationById(productId);
    }

    @ApiOperation("根据商品系列号获取商品列表")
    @PostMapping("/api/product/get_product_by_num")
    public BaseResult<List<ProductVO>> getProductByNum(@RequestParam("productSeriesNum") String productSeriesNum){
        return productService.getProductByNum(productSeriesNum);
    }

    @ApiOperation("点播视频添加在售商品")
    @PostMapping("/addVodProduct")
    public BaseResult addVodProduct(@RequestBody @Validated AddVodProductDto dto){
         productService.addVodProduct(dto);
         return BaseResult.doSuccess(null,"添加成功");
    }

    @ApiOperation("点播商品记录点击次数")
    @PostMapping("/addVodProductClickInfo")
    public BaseResult addVodProductClickInfo(@Validated @RequestBody VodProductClickDto dto){
        productService.addVodProductClickInfo(dto);
        return BaseResult.doSuccess(null,"记录成功");
    }
    @ApiOperation("定时任务将点播商品详情存入数据库")
    @PostMapping("/addVodProductClickJob")
    public BaseResult addVodProductClickJob() {
        productService.addVodProductClickJob();
        return BaseResult.doSuccess(null, "执行成功");
    }
}
